#include "ukuiwindow.h"

#include "wayland-ukui-window-management-client-protocol.h"
namespace ukuiwaylandclient
{

UkuiWindow::UkuiWindow(const QString &uuid, uint32_t id)
    : m_uuid(uuid)
    , m_objectId(id)
{
    // Initialize other properties if needed
}

QString UkuiWindow::uuid() const
{
    return m_uuid;
}

uint32_t UkuiWindow::objectId() const
{
    return m_objectId;
}

void UkuiWindow::setTitle(const QString &title)
{
    m_title = title;

    Q_EMIT titleChanged(title); // Emit signal when title changes
}

QString UkuiWindow::title() const
{
    return m_title;
}

void UkuiWindow::setAppId(const QString &appId)
{
    m_appId = appId;
    Q_EMIT appIdChanged(appId);
}

QString UkuiWindow::appId() const
{
    return m_appId;
}

void UkuiWindow::setPid(int32_t pid)
{
    m_pid = pid;
    Q_EMIT pidChanged(pid);
}

int32_t UkuiWindow::pid() const
{
    return m_pid;
}

void UkuiWindow::setGeometry(const QRect &geometry)
{
    m_geometry = geometry;
    Q_EMIT geometryChanged(geometry);
}

QRect UkuiWindow::geometry() const
{
    return m_geometry;
}

void UkuiWindow::setThemedIconName(const QString &name)
{
    m_themedIconName = name;
    Q_EMIT themedIconNameChanged(name);
}

QString UkuiWindow::themedIconName() const
{
    return m_themedIconName;
}

void UkuiWindow::setResourceName(const QString &name)
{
    m_resourceName = name;
    Q_EMIT resourceNameChanged(name);
}

QString UkuiWindow::resourceName() const
{
    return m_resourceName;
}

void UkuiWindow::setParentWindow(UkuiWindow *parent)
{
    m_parent = parent;
    Q_EMIT parentWindowChanged(parent);
}

UkuiWindow *UkuiWindow::parentWindow() const
{
    return m_parent;
}

void UkuiWindow::setVirtualDesktop(const QString &virtualDesktopId)
{
    m_virtualDesktopId = virtualDesktopId;
    Q_EMIT virtualDesktopChanged(virtualDesktopId);
}

QString UkuiWindow::virtualDesktop() const
{
    return m_virtualDesktopId;
}

void UkuiWindow::setState(uint32_t state)
{
    m_state = state;
    Q_EMIT stateChanged(state); // Emit signal when state changes
}

bool UkuiWindow::isActive() const
{
    return m_state & UKUI_WINDOW_STATE_ACTIVE;
}

bool UkuiWindow::isMinimized() const
{
    return m_state & UKUI_WINDOW_STATE_MINIMIZED;
}

bool UkuiWindow::isMaximized() const
{
    return m_state & UKUI_WINDOW_STATE_MAXIMIZED;
}

bool UkuiWindow::isFullScreen() const
{
    return m_state & UKUI_WINDOW_STATE_FULLSCREEN;
}

bool UkuiWindow::isKeepAbove() const
{
    return m_state & UKUI_WINDOW_STATE_KEEP_ABOVE;
}

bool UkuiWindow::isKeepBelow() const
{
    return m_state & UKUI_WINDOW_STATE_KEEP_BELOW;
}

bool UkuiWindow::isOnAllDesktops() const
{
    return m_state & UKUI_WINDOW_STATE_ON_ALL_DESKTOPS;
}

bool UkuiWindow::isDemandsAttention() const
{
    return m_state & UKUI_WINDOW_STATE_DEMANDS_ATTENTION;
}

bool UkuiWindow::isCloseable() const
{
    return m_state & UKUI_WINDOW_STATE_CLOSEABLE;
}

bool UkuiWindow::isMinimizable() const
{
    return m_state & UKUI_WINDOW_STATE_MINIMIZABLE;
}

bool UkuiWindow::isMaximizable() const
{
    return m_state & UKUI_WINDOW_STATE_MAXIMIZABLE;
}
bool UkuiWindow::isFullScreenable() const
{
    return m_state & UKUI_WINDOW_STATE_FULLSCREENABLE;
}
bool UkuiWindow::isShadeable() const
{
    return m_state & UKUI_WINDOW_STATE_SHADEABLE;
}
bool UkuiWindow::isShaded() const
{
    return m_state & UKUI_WINDOW_STATE_SHADED;
}
bool UkuiWindow::isMovable() const
{
    return m_state & UKUI_WINDOW_STATE_MOVABLE;
}
bool UkuiWindow::isResizable() const
{
    return m_state & UKUI_WINDOW_STATE_RESIZABLE;
}
bool UkuiWindow::isVirtualDesktopChangeable() const
{
    return m_state & UKUI_WINDOW_STATE_VIRTUAL_DESKTOP_CHANGEABLE;
}
bool UkuiWindow::isAcceptFocus() const
{
    return m_state & UKUI_WINDOW_STATE_ACCEPT_FOCUS;
}
bool UkuiWindow::isSkipTaskbar() const
{
    return m_state & UKUI_WINDOW_STATE_SKIPTASKBAR;
}
bool UkuiWindow::isSkipSwitcher() const
{
    return m_state & UKUI_WINDOW_STATE_SKIPSWITCHER;
}

bool UkuiWindow::isModality() const
{
    return m_state & UKUI_WINDOW_STATE_MODALITY;
}

QDebug operator<<(QDebug dbg, const UkuiWindow *window)
{
    if (window) {
        dbg.nospace() << "\n"
                      << "Uuid: " << window->m_uuid << "\n"
                      << "Title: " << window->m_title << "\n"
                      << "AppId: " << window->m_appId << "\n"
                      << "PID: " << window->m_pid << "\n"
                      << "Geometry: " << window->m_geometry << "\n"
                      << "ThemedIconName: " << window->m_themedIconName << "\n"
                      << "ResourceName: " << window->m_resourceName << "\n"
                      << "ParentWindow: " << (window->m_parent ? window->m_parent->uuid() : QString("None")) << "\n"
                      << "VirtualDesktop: " << window->m_virtualDesktopId << "\n"
                      << "Active: " << window->isActive() << "\n"
                      << "Minimized: " << window->isMinimized() << "\n"
                      << "Maximized: " << window->isMaximized() << "\n"
                      << "FullScreen: " << window->isFullScreen() << "\n"
                      << "KeepAbove: " << window->isKeepAbove() << "\n"
                      << "KeepBelow: " << window->isKeepBelow() << "\n"
                      << "OnAllDesktops: " << window->isOnAllDesktops() << "\n"
                      << "DemandsAttention: " << window->isDemandsAttention() << "\n"
                      << "Closeable: " << window->isCloseable() << "\n"
                      << "Minimizable: " << window->isMinimizable() << "\n"
                      << "Maximizable: " << window->isMaximizable() << "\n"
                      << "FullScreenable: " << window->isFullScreenable() << "\n"
                      << "Shadeable: " << window->isShadeable() << "\n"
                      << "Shaded: " << window->isShaded() << "\n"
                      << "Movable: " << window->isMovable() << "\n"
                      << "Resizable: " << window->isResizable() << "\n"
                      << "VirtualDesktopChangeable: " << window->isVirtualDesktopChangeable() << "\n"
                      << "SkipTaskbar: " << window->isSkipTaskbar() << "\n"
                      << "SkipSwitcher: " << window->isSkipSwitcher() << "\n"
                      << "AcceptFocus: " << window->isAcceptFocus() << "\n"
                      << "Modality: " << window->isModality() << "\n";
    }
    return dbg.space();
}

} // namespace ukuiwaylandclient
